// 已移除的 mock 数据与 fetch* 方法；仅保留类型与工具函数。

export type AttributeControlType = 'TextBox' | 'NumericTextBox' | 'DropDownList' | 'checkbox';

export interface MaterialAttributeDefinition {
  code: string;
  name: string;
  control: AttributeControlType;
  required?: boolean;
  unit?: string;
  optionKey?: string; // 后端属性若映射为下拉，可使用原 optionKey 作标识（非必需）
  placeholder?: string;
  remark?: string;
  group?: 'size' | 'basic' | 'remark';
}

export interface AttributeOptionItem { value: string; label: string; }

// 规格摘要构建：优先使用 长×宽×高 / 长×宽，其次首个必填字段，再任意一个非空值
export function buildAttributeSpec(category: string, values: Record<string, any>, defs: MaterialAttributeDefinition[]): string {
  const len = values['length'];
  const width = values['width'];
  const height = values['height'];
  if (len && width && height) return `${len}×${width}×${height}`;
  if (len && width) return `${len}×${width}`;
  const primary = defs.find(d => d.required && values[d.code] != null && values[d.code] !== '');
  if (primary) return String(values[primary.code]);
  const any = Object.keys(values).find(k => values[k] !== undefined && values[k] !== '');
  return any ? String(values[any]) : '';
}

export interface DynamicAttributePayload { definitions: MaterialAttributeDefinition[]; values: Record<string, any>; }

